/**
 * 
 */
package com.eagle.coders.mybatis.mapper.generator;

import java.util.HashMap;
import java.util.Map;

import com.eagle.coders.common.ui.form.renderer.BeansAnnotationProcessor;
import com.eagle.coders.core.exceptions.BaseAppException;
import com.eagle.coders.core.template.handler.TemplateLoader;
import com.eagle.coders.core.type.AnnotationRetrivalType;
import com.eagle.coders.core.type.TemplateType;

/**
 * @author Anees
 *
 */
public class MyBatisMapperGenerator {
	
	/**
	 * 
	 * @param beanClass
	 * @param conditionTypeMap
	 * @return
	 */
	public Map<String, String> getMapper(String beanClass, Map<String, Object> conditionTypeMap){
		Map<String, Object> tableProperties =
			BeansAnnotationProcessor.getValueOfNamedAnnotation(beanClass, AnnotationRetrivalType.TABLE);
		String name = BeansAnnotationProcessor.getClassName(beanClass);
		Map<String, Object> toInject = new HashMap<String, Object>();
		toInject.put("beanClass", beanClass);
		toInject.put("beanName", name);
		toInject.put("beanTableName", tableProperties.get("beanTableName"));
		if(null != conditionTypeMap && conditionTypeMap.size()!= 0){
			toInject.put("searchConditions", conditionTypeMap);
		}
		String sourceName = name+"Mapper";
		
		Map<String, String> sourceWithNameMap = new HashMap<String, String>();
		try{
		sourceWithNameMap.put(sourceName, TemplateLoader.getInstance().getTemplate(TemplateType.MYBATIS, toInject));
		}catch(BaseAppException bae ){
			bae.printStackTrace();//TODO:
		}
//		return TemplateLoader.getInstance().getTemplate(TemplateType.MYBATIS, toInject);
		return sourceWithNameMap;
	}

}
